<template>
	<!--
	<view class="message-item-wrap" @click="onClick">
		<view class="message-box">
			<image :src="data.avatar" class="message-img"></image>
			<view class="message-mod">
				<view class="message-mod-line">
					<view class="message-mod-name nowrap">
						<text lines="1" class="message-mod-txt1">{{ data.nick }}</text>
						<text v-if="type == 1" lines="1" decode="true" class="message-mod-txt2">{{ custom.hospName }}&nbsp;&nbsp;{{ custom.ksName }}</text>
						<text v-if="type == 0" lines="1" decode="true" class="message-mod-txt2">{{ custom.sex==2?'女':'男'}}</text>
					</view>
					<view lines="1" class="message-mod-time">{{ time }}</view>
				</view>

				<view class="message-mod-info nowrap">{{ judgeMessageTypeast }}</view>
			</view>
		</view>
		<view class="message-num" v-if="data.unread">{{ data.unread }}</view>
	</view>
	-->
	<view class="message-item-wrap" @click="onClick">
		<view class="message-box">
			<image :src="data.userProfile.avatar" class="message-img"></image>
			<view class="message-mod">
				<view class="message-mod-line">
					<view class="message-mod-name nowrap">
						<text lines="1" class="message-mod-txt1">{{ data.userProfile.nick }}</text>
						<text v-if="type == 1" lines="1" decode="true" class="message-mod-txt2">{{ hospName }}&nbsp;&nbsp;{{ ksName }}</text>
						<text v-if="type == 0" lines="1" decode="true" class="message-mod-txt2">{{ data.userProfile.gender }}</text>
					</view>
					<view lines="1" class="message-mod-time">{{ time }}</view>
				</view>
	
				<view class="message-mod-info nowrap">{{ judgeMessageTypeast }}</view>
			</view>
		</view>
		<view class="message-num" v-if="data.unreadCount">{{ data.unreadCount }}</view>
	</view>
</template>

<script>
import { calcTimeHeader } from '@/utils-im/util.js';
const app = getApp();
export default {
	props: {
		data: {
			type: Object,
			default() {
				return {};
			}
		},
		type: {
			type: Number | String,
			default: 0
		}
	},
	data() {
		return {
			hospName: '',
			ksName: ''
		};
	},

	computed: {
		/*
		custom() {
			return JSON.parse(this.data.custom);
		},
		*/
		/*
		time() {
			return calcTimeHeader(this.data.lastMsg.time);
		},
		*/
		time() {
			return calcTimeHeader(this.data.lastMessage.lastTime * 1000);
		},
	   /*
		judgeMessageTypeast() {
			let type = this.data.lastMsg.type;

			let msgType = '';
			switch (type) {
				case 'image':
					msgType = '[图片]';
					break;
				case 'geo':
					msgType = '[位置]';
					break;
				case 'audio':
					msgType = '[语音]';
					break;
				case 'video':
					msgType = '[视频]';
					break;
				case 'image':
					msgType = '[提醒消息]';
					break;
				case 'custom':
					msgType = '[自定义消息]';
					break;
				case 'deleteMsg':
					msgType = '[消息已撤回]';
					break;
				case 'tip':
					msgType = '[提示消息]';
					break;
				case 'file':
					msgType = '[文件消息]';
					break;
				case '白板消息':
					msgType = '[白板消息]';
					break;
				case '阅后即焚':
					msgType = '[阅后即焚]';
					break;
				case 'robot':
					msgType = '[机器人消息]';
					break;
				case 'notification':
					msgType = '[通知消息]';
					break;
				default:
					msgType = this.data.lastMsg.text;
			}
			return msgType;
		}
		*/
		judgeMessageTypeast() {
			const TIM = app.globalData.TIM;
			let type = this.data.lastMessage.type;

			let msgType = '';
			switch (type) {
				case TIM.TYPES.MSG_IMAGE:
					msgType = '[图片]';
					break;
				case TIM.TYPES.MSG_LOCATION:
					msgType = '[位置]';
					break;
				case TIM.TYPES.MSG_AUDIO:
					msgType = '[语音]';
					break;
				case TIM.TYPES.MSG_VIDEO:
					msgType = '[视频]';
					break;
				case TIM.TYPES.MSG_IMAGE:
					msgType = '[提醒消息]';
					break;
				case TIM.TYPES.MSG_CUSTOM:
					msgType = '[自定义消息]';
					break;
				case 'deleteMsg':
					msgType = '[消息已撤回]';
					break;
				case TIM.TYPES.MSG_GRP_TIP:
					msgType = '[提示消息]';
					break;
				case TIM.TYPES.MSG_FILE:
					msgType = '[文件消息]';
					break;
				case '白板消息':
					msgType = '[白板消息]';
					break;
				case '阅后即焚':
					msgType = '[阅后即焚]';
					break;
				case 'robot':
					msgType = '[机器人消息]';
					break;
				case TIM.TYPES.MSG_GRP_SYS_NOTICE:
					msgType = '[通知消息]';
					break;
				default:
					msgType = this.data.lastMessage.payload.text;
			}
			return msgType;
		}
	},
	onLoad(option) {
	},
	mounted() {
		if (this.type === 1) {
			app.globalData.tim.getUserProfile({
				userIDList: [this.data.userProfile.userID]
			}).then(imResponse => {
				const profileList = imResponse.data;
				if (profileList && profileList.length > 0) {
					const profile = profileList[0]
					const profileCustomField = profile.profileCustomField;
					const hospName = profileCustomField[0].value
					const ksName = profileCustomField[1].value
					this.hospName = hospName
					this.ksName = ksName
				}
			}).catch(imError => {
				console.error(imError);
			})
		}
	},
	onShow() {},
	methods: {
		onClick() {
			this.$emit('click');
		}
	}
};
</script>

<style lang="less" >
.message-item-wrap {
	width: 750rpx;
	height: 160rpx;
	background-color: #fff;
	margin-top: 2rpx;
	justify-content: center;
	align-items: center;
	position: relative;
	display: flex;
	flex-direction: column;
	padding: 0;
	.message-box {
		width: 687rpx;
		height: 96rpx;
		flex-direction: row;
		display: flex;
		.message-img {
			border-radius: 50%;
			width: 96rpx;
			height: 96rpx;
		}

		.message-mod {
			width: 560rpx;
			height: 92rpx;
			display: flex;
			flex-direction: column;
			margin: 2rpx 0 0 24rpx;
			.message-mod-line {
				display: flex;
				justify-content: space-between;
				.message-mod-name {
					width: 400rpx;
					display: flex;
					.message-mod-txt1 {
						font-weight: bold;
						display: block;
						overflow-wrap: break-word;
						color: rgba(25, 31, 37, 1);
						font-size: 34rpx;
						margin-right: 42rpx;
						font-family: PingFangSC-Regular;
						white-space: nowrap;
						line-height: 44rpx;
						text-align: left;
					}
					.message-mod-txt2 {
						display: block;
						overflow-wrap: break-word;
						color: rgba(25, 31, 37, 0.4);
						font-size: 24rpx;
						font-family: PingFangSC-Regular;
						white-space: nowrap;
						line-height: 32rpx;
						text-align: left;
						margin-top: 6rpx;
					}
				}

				.message-mod-time {
					color: rgba(25, 31, 37, 0.28);
					font-size: 24rpx;
					font-family: PingFangSC-Regular;
					text-align: right;
					line-height: 44rpx;
				}
			}
		}

		.message-mod-info {
			width: 550rpx;
			color: rgba(25, 31, 37, 0.4);
			font-size: 28rpx;
			font-family: PingFangSC-Regular;
			margin-top: 10rpx;
		}
	}

	.message-num {
		line-height: 33rpx;
		text-align: center;
		color: rgba(255, 255, 255, 1);
		font-size: 22rpx;
		font-family: PingFangSC-Regular;
		position: absolute;
		left: 99rpx;
		top: 31rpx;
		width: 34rpx;
		height: 34rpx;
		border-radius: 50%;
		border: 1rpx solid rgba(255, 255, 255, 1);
		background-color: rgba(242, 86, 67, 1);
		display: flex;
		flex-direction: column;
	}
}
</style>
